<?php
namespace Common\Model;
use Think\Model;
class CustBlackListModel extends Model {
	protected $connection = 'DB_BASE_DSN';
	protected $tableName = 'qyx_cust_blacklist'; 
	
	
	public function getDistinctCustId($custid){
		if($custid > 0)$map['custid']  = $custid;
		
		$fields = array('custid');
		$result = $this->field($fields)->where($map)->select();
		return $result;
	}
	
	public function getBlacklistIdsByCustId($custid){
		$map['custid']  = $custid;
		
		$fields = array('tcustid');
		$result = $this->field($fields)->where($map)->select();
		return $result;
	}
	
	public function getBlacklistCust($custid,$tcustid){
		$map['custid']  = $custid;
		$map['tcustid']  = $tcustid;
	
		$result = $this->where($map)->find();
		return $result;
	}
	
	
	public function addBlacklist($data){
		$map['custid'] = $data['custid'];
		$map['tcustid'] = $data['tcustid'];
		$ret = $this->where($map)->find();
		if(!empty($ret)){
			return $ret['id'];
		}else{
			$result = $this->add($data);
			return $result;
		}
	}
	
	
	public function deleteBlacklist($data){
		$map['custid'] = $data['custid'];
		$map['tcustid'] = $data['tcustid'];
		$result = $this->where($map)->delete();
		return $result;
	}
}


